#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<cstring>
#include<stack>
using namespace std;
long long ans;long int T;
long long ls, i, j, z;
char s[100005];
stack<char>s1[10005], s2;
int main()
{
	while (1) {
		cin.getline(s, 100005);
		ls = strlen(s);
		if (ls == 3 && s[0] == 'E' && s[1] == 'O' && s[2] == 'F') break;
		for (j = 0; j < ls; j++) {
			if (s[j] == '<' && s1[i].empty() == 0)s1[i].pop();
			else if (s[j] >= 'a' && s[j] <= 'z' || s[j] == '.' || s[j] == ' ')s1[i].push(s[j]);
		}
		i++;
	}
	while (1) {
		cin.getline(s, 100005);
		ls = strlen(s);
		if (ls == 3 && s[0] == 'E' && s[1] == 'O' && s[2] == 'F' || z >= i)break;
		for (j = 0; j < ls; j++) {
			if (s[j] == '<' && s2.empty()==0)s2.pop();
			else if (s[j] >= 'a' && s[j] <= 'z' || s[j] == '.' || s[j] == ' ')s2.push(s[j]);
		}
		stack<char>t1, t2;
		while (s1[z].empty() == 0) {
			t1.push(s1[z].top());
			s1[z].pop();
		}
		z++;
		while (s2.empty() == 0) {
			t2.push(s2.top());
			s2.pop();
		}
		ls = min(t1.size(), t2.size());
		for (j = 0; j < ls; j++) {
			if (t1.top() == t2.top())ans++;
			t1.pop();
			t2.pop();
		}
	}
	cin >> T;
	cout << (int)((double)ans / (double)T * 60.0 + 0.5);
	return 0;
}


//#include<cstring>
//using namespace std;
//int i = -1, j = -1, z, digit1, digit2;
//long long ans; int ls;
//int flag; int T;
//string str[10000];
//string strr[10000];
//int main()
//{
//	string ar;
//	do {
//		i++;
//		getline(cin, str[i]);
//	} while (str[i] != "EOF");
//	do {
//		j++;
//		getline(cin, strr[j]);
//	} while (strr[i] != "EOF");
//	for ( z = 0; z < i && z < j; z++) {
//		while (strr[z][digit2] != '\0') {
//			if (strr[z][digit2] != '\0' && strr[z][digit2 + 1] == '<') { digit2 += 2; continue; }
//			if (strr[z][digit2] == '<') { digit2++; continue; }
//			if (str[z][digit1] != '\0' && str[z][digit1 + 1] == '<') { digit1 += 2; continue; }
//			if (str[z][digit1] == '<') { digit1++; continue; }
//			if (str[z][digit1] == strr[z][digit2]&&str[z][digit1]!='\0')ans++;
//			digit1++; digit2++;
//		}
//		digit1 = digit2 = 0;
//	}
//	cin >> T;
//	cout << (int)((double)ans / (double)T * 60.0 + 0.5);
//	return 0;
//}


//#include<iostream>
//#include<string>
//#include<cstring>
//using namespace std;
//int i = -1, j, digit;
//long long ans;int ls;
//int flag; int T;
//string str[10000];
//int main()
//{
//	char ch;
//	string ar;
//	do {
//		i++;
//		getline(cin, str[i]);
//	} while (str[i] != "EOF");
//	//for (int a = 0; a < i; a++)cout << str[a];
//	for (j = 0;j < i; j++) {
//		int ll = str[j].size();
//		while ((ch=getchar()) != '\n') {
//			if (ch == '<'){
//				if(flag)ans--;
//				digit--;
//				flag = 0;
//				continue;
//			}
//			flag = 0;
//			if (digit < ll && str[j][digit] == ch) { ans++; flag = 1; }
//			digit++;
//		}
//		digit = 0;
//	}
//	do {
//		getline(cin, ar);
//	} while (ar != "EOF");
//	cin >> T;
//	cout << (int)((double)ans / (double)T * 60.0 + 0.5);
//	return 0;
//}